<?php if (!defined('PmWiki')) exit();
/**
  PreviewChanges for PmWiki
  Written by (c) Petko Yotov 2011 www.pmwiki.org/Petko
  
  This text is written for PmWiki; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published
  by the Free Software Foundation; either version 3 of the License, or
  (at your option) any later version. See pmwiki.php for full details
  and lack of warranty.
*/
# Version date
$RecipeInfo['PreviewChanges']['Version'] = '20111019';

if(@$_REQUEST['preview']=='') return;

include_once("$FarmD/scripts/pagerev.php");
$EditFunctions[] = 'PreviewChanges';

function PreviewChanges($pagename,&$page,&$new) {
  global $FmtV, $DiffFunction, $DiffHTMLFunction, $EnableDiffInline, $DiffShow;
  if (@$_REQUEST['preview']>'' && @$page['text']>'' && $page['text']!=$new['text']) {
    $d = IsEnabled($DiffShow['source'], 'y');
    $e = IsEnabled($EnableDiffInline, 1);
    $DiffShow['source'] = 'y';
    $EnableDiffInline = 1;
    SDV($DiffHTMLFunction, 'DiffHTML');
    $diff = $DiffFunction($new['text'], $page['text']);# reverse the diff
    $FmtV['$PreviewText'] = $DiffHTMLFunction($pagename, $diff).'<hr/>'.@$FmtV['$PreviewText'];
    $DiffShow['source'] = $d;
    $EnableDiffInline = $e;
  }
}
